<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@page import="com.yaodian100.core.common.utils.ServerValue"%>
<head>
<style type="text/css">
h1 span{visibility:visible;}
td span{visibility:visible;}
.msg{float:left; line-height:1em; margin:0; display:block;border:1px solid #f66;padding:2px 5px;*padding:2px 5px 1px;}
.msg.rn{background-color:#fff2f2;border-color:#f66;}
</style>
</head>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath() %>'/>
<c-rt:set var="frontHostname" value='<%=ServerValue.getFrontHostname() %>'/>
<!-- 数字验证 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<script type="text/javascript" charset="UTF-8" src="/js/yaodian100.common.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.autotab-1.1b.js"></script>
<script language="javascript">
	$().ready( function() {

		$(":input[name*='ProdId']").each(function(){
			$("#" + this.id).numeric();
			$(this).blur(function(){
				$(this).val(prodPadLeft($(this).val()));
				getProductInfo2("${midContextPath}",this.id.substring(0,4) + "Name",$(this).val());
			});
		});

		$(":input[id*='adWord']").alphanumeric();
		$(":input[id*='adWord']").autotab_filter({ format: 'custom', pattern: '[^a-zA-Z0-9]' });
		
		$('#startDate').datepick({minDate: new Date(), showOn:'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"}); 
		$('#endDate').datepick({minDate: new Date(),showOn: 'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"});
		$("#subBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("10");
				$("#idxHotSaleAdvForm").submit();
			}
		});

		$("#draftBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("00");
				$("#idxHotSaleAdvForm").submit();
			}
		});
		
		$("#canBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("90");
				$("#idxHotSaleAdvForm").submit();
			}
		});
	});
	
	function validate_data(){
		//var isCorrect = true;
		//$("span:[id*=Tip]").hide();
		//$("span:[id*=Tip]").text('');
		if ( $("#advName").val() == "" ){
			alert("请输入广告名称");
			$("#advName").focus();
			return false;
			//$("#advNameTip").text("请输入广告名称");
			//$("#advNameTip").show();
			//isCorrect = false;
		}
		if ( $("#startDate").val() == ""){
			alert("请输入起始时间");
			$("#startDate").focus();
			return false;
			//$("#startDateTip").text("请输入起始时间");
			//$("#startDateTip").show();
			//isCorrect = false;
		}

		if( $("#endDate").val() == "" ){
			alert("请输入结束时间");
			$("#endDate").focus();
			return false;
			//$("#endDateTip").text("请输入结束时间");
			//$("#endDateTip").show();
			//isCorrect = false;
		}
		if($('#startDate').val()>$('#endDate').val()){
			alert('结束日期不能小于起始日期');
			$("#endDate").focus();
			return false;
			//$('#endDateTip').text('结束日期不能小于起始日期');
			//$('#endDateTip').show();
			//$('#endDate').focus();
			//isCorrect = false;
		}else if($('#startDate').val()==$('#endDate').val()){
			if($('#startTime').val()>=$('#endTime').val()){
				alert('结束时间需大于起始时间');
				$("#endTime").focus();
				return false;
				//$('#endTimeTip').text('结束时间需大于起始时间');
				//$('#endTimeTip').show();
				//$('#endTime').focus();
				//isCorrect = false;
			}
		}
		for( var i = 1; i <= 4; i++ ){
			if ( $("#tab" + i + "ProdId").val() == "" ){
				alert("请输入Tab"+i+"商品编号");
				 $("#tab" + i + "ProdId").focus();
				return false;
				//appendWord($("#tab" + i + "Tip"),"请输入商品编号");
				//$("#tab" + i + "Tip").show();
				//isCorrect = false;
			}

			if ( $("#tab" + i + "Name").val() == "" ){
				alert("请输入Tab"+i+"商品名称");
				$("#tab" + i + "Name").focus();
				return false;
				//appendWord($("#tab" + i + "Tip"),"请输入商品名称");
				//$("#tab" + i + "Tip").show();
				//isCorrect = false;
			}
		}
		return true;
	}

	function appendWord(origin, apptext){
		if(origin.text().length==0){
			origin.text(apptext);
		}else{
			origin.text(origin.text()+', '+apptext);
		}
		
	}
</script>
<s:if test="hasErrors()">
<p><s:actionerror cssClass="msg rn" /></p>
</s:if>
<s:if test="hasActionMessages()">
<p><s:actionmessage cssClass="msg rn" /></p>
</s:if>
<s:if test="hasFieldErrors()">
<p><s:fielderror cssClass="msg rn" /></p>
</s:if>
<h1>广告管理</h1>
<s:form action="idxHotSaleV2/saveIdxHotSaleAdv.do" method="post" name="idxHotSaleAdvForm" id="idxHotSaleAdvForm" enctype="multipart/form-data">
	<table class="tb-data" width="100%">
		<tbody>
			<tr>
				<th>类型</th>
				<td>首页热销商品V2<input type="hidden" name="advType" id="advType" value="${advType}"/></td>
			</tr>
			<tr>
				<th>广告名称</th>
				<td><input type="text" id="advName" name="advName" value="${advName}" size="30" maxlength="30"/><br/><span id="advNameTip" class="msg rn" style="display:none;"></span></td>
			</tr>
			<tr>
				<th>起迄时间</th>
				<td>
				<input type="text" id="startDate" name="startDate" value="${startDate}" maxlength="10"/>
				<select id="startTime" name="startTime">			
					<c-rt:forEach begin="0" end="23" var="t1">
						<c-rt:if test="${t1<10}">
						<c-rt:set value="0${t1}:00" var="sTime"></c-rt:set>
						</c-rt:if>
						<c-rt:if test="${t1>=10}">
						<c-rt:set value="${t1}:00" var="sTime"></c-rt:set>
						</c-rt:if>
						<option value="${sTime}" <c-rt:if test="${sTime==startTime}">selected</c-rt:if>>${sTime}</option>
					</c-rt:forEach>
				</select> ~ 				 
				<input type="text" id="endDate" name="endDate" value="${endDate}" maxlength="10"/>
				<select id="endTime" name="endTime">
					<c-rt:forEach begin="0" end="23" var="t2" >
						<c-rt:set var="t3">${23-t2}</c-rt:set>	
						<c-rt:if test="${t3<10}">
						<c-rt:set value="0${t3}:59" var="eTime"></c-rt:set>
						</c-rt:if>
						<c-rt:if test="${t3>=10}">
						<c-rt:set value="${t3}:59" var="eTime"></c-rt:set>
						</c-rt:if>
						<option value="${eTime}" <c-rt:if test="${eTime==endTime }">selected</c-rt:if>>${eTime}</option>
					</c-rt:forEach>
				</select>
				<br/>
				<span id="startDateTip" class="msg rn" style="display:none;"></span><span id="startTimeTip" class="msg rn" style="display:none;"></span><span id="endDateTip" class="msg rn" style="display:none;"></span><span id="endTimeTip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<th colspan="4">tab设定</th>
			</tr>
			<tr>
				<th>Tab1</th>
				<td>
					<b>商品编号</b><input type="text" name="tab1ProdId" id="tab1ProdId" maxlength="8" size="10" value="${tab1ProdId}"/><br/>
					<b>商品名称:</b><input type="text" name="tab1Name" id="tab1Name" value="${tab1Name}" maxlength="20" size="50"/><br/>
					<b>广告代码:</b><input type="text" name="tab1adWord" id="tab1adWord" value="${tab1adWord}" size="20" maxlength="25"/><span>非必填。由英文字母、数字组成，最多25个半角</span><br/>	
					<span id="tab1Tip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<th>Tab2</th>
				<td>
					<b>商品编号</b><input type="text" name="tab2ProdId" id="tab2ProdId" maxlength="8" size="10" value="${tab2ProdId}"/><br/>
					<b>商品名称:</b><input type="text" name="tab2Name" id="tab2Name" value="${tab2Name}" maxlength="20" size="50"/><br/>
					<b>广告代码:</b><input type="text" name="tab2adWord" id="tab2adWord" value="${tab2adWord}" size="20" maxlength="25"/><span>非必填。由英文字母、数字组成，最多25个半角</span><br/>
					<span id="tab2Tip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<th>Tab3</th>
				<td>
					<b>商品编号</b><input type="text" name="tab3ProdId" id="tab3ProdId" maxlength="8" size="10" value="${tab3ProdId}"/><br/>
					<b>商品名称:</b><input type="text" name="tab3Name" id="tab3Name" value="${tab3Name}" maxlength="20" size="50"/><br/>
					<b>广告代码:</b><input type="text" name="tab3adWord" id="tab3adWord" value="${tab3adWord}" size="20" maxlength="25"/><span>非必填。由英文字母、数字组成，最多25个半角</span><br/>
					<span id="tab3Tip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<th>Tab4</th>
				<td>
					<b>商品编号</b><input type="text" name="tab4ProdId" id="tab4ProdId" maxlength="8" size="10" value="${tab4ProdId}"/><br/>
					<b>商品名称:</b><input type="text" name="tab4Name" id="tab4Name" value="${tab4Name}" maxlength="20" size="50"/><br/>
					<b>广告代码:</b><input type="text" name="tab4adWord" id="tab4adWord" value="${tab4adWord}" size="20" maxlength="25"/><span>非必填。由英文字母、数字组成，最多25个半角</span><br/>
					<span id="tab4Tip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>			
			<tr>
				<td colspan="2">
					<input type="hidden" id="advId" name="advId" value="${advId}"/>
					<input type="hidden" id="advStatus" name="advStatus" value="${advStatus}"/>
					<input type="button" id="subBtn" name="subBtn" value="发送"/>
					<input type="button" id="draftBtn" name="draftBtn" value="草稿"/>
					<input type="button" id="canBtn" name="canBtn" value="暂停"/>
				</td>
			</tr>												
		</tbody>
	</table>
</s:form>
<div class="f-link">
	<a href="${midContextPath}/generate/searchIdx.do">回广告查询页</a>
</div>